﻿using System.ComponentModel;
using Pfz.RemoteGaming.Internal;

namespace Pfz.RemoteGaming
{
	/// <summary>
	/// RemoteGameComponent that implements INotifyPropertyChanged.
	/// </summary>
	public abstract class ObservableRemoteGameComponent:
		RemoteGameComponent,
		INotifyPropertyChanged
	{
		#region Fields
			private _NotifyPropertyChangedEventArgs _args = new _NotifyPropertyChangedEventArgs();
		#endregion

		#region OnChanged
			/// <summary>
			/// Overriden to call PropertyChanged event.
			/// </summary>
			protected internal override void OnChanged(RemoteGamePropertyChanges changes)
			{
				base.OnChanged(changes);

				var handler = PropertyChanged;
				if (handler != null)
				{
					foreach(var pair in changes)
					{
						_args._propertyName = pair.Key._name;
						handler(this, _args);
					}
				}
			}
		#endregion

		#region PropertyChanged
			/// <summary>
			/// Event invoked on the client side when properties are changed from the server side.
			/// </summary>
			public event PropertyChangedEventHandler PropertyChanged;
		#endregion
	}
}
